package com.arlen.conf;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;

public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    private final  String url ;

    public MyAuthenticationSuccessHandler(String url) {
        this.url = url;
    }
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
//        System.out.println(authorities);
//        Object details = authentication.getDetails();
//        System.out.println(details);
//        Object details1 = authentication.getDetails();
//        System.out.println(details1);
//        Object credentials = authentication.getCredentials();
//        System.out.println(credentials);
        response.sendRedirect(url);
    }
}
